Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@formsort/web-embed-api
Advanced tools
Embed Formsort flows within other webpages, with communication between the embed and the parent page.
If you're using React, see @formsort/react-embed which is a handy wrapper around this.
First, install
npm install @formsort/web-embed-api --save
Then, initialize the embed and load a flow.
Initializes a Formsort iframe as a child of the rootEl
provided.
The config
has the following interface:
interface IFormsortWebEmbedConfig {
useHistoryAPI?: boolean; // Default: false
autoHeight?: boolean; // Default: false
style?: {
width?: CSSStyleDeclaration['width'];
height?: CSSStyleDeclaration['height'];
};
}
config
propertiesuseHistoryAPI
: When redirecting, should we use the HTML5 History API (namely, window.pushState
), or just change the URL in its entirety?
Helpful if you have a single-page app and want to change the container's URL without reloading the entire page. Note that you'll have to listen to the popstate
event on the embedding window
to detect this navigation.
autoHeight
: Should the embedding <iframe>
resize so that it matches the content of the currently loaded flow?
style
CSS properties to be applied to the iframe container.
loadFlow(clientLabel: string, flowLabel: string, variantLabel?: string, queryParams?: Array<[string, string]>) => void
Starts loading a Formsort variant, or a flow.
Note that variantLabel is optional: if it is not provided, a variant will be chosen at random from that flow.
setSize(width: number, height: number) => void
Set the CSS size of the embed.
You may also style the embed's iframe using CSS - it is the iframe child of the rootEl
, so you'd use the selector #rootEl > iframe
.
addEventListener(eventName: key of IEventMap, fn: IEventMap[eventName]) => void
The events include:
() => void
Set a callback function to be called when the Formsort flow has loaded completely.
Note that this is more accurate than listening for the iframe's load
event, as this is sent from within the Formsort application code and not merely when the DOM is loaded.
You can listen for this to do things like hide the frame container, or display a loading indicator, until everything is loaded to ensure a seamless initial experience.
const embed = FormsortWebEmbed(document.body);
embed.addEventListener('flowloaded', () => {
console.log('Flow has loaded!');
})
embed.loadFlow('formsort', 'onboarding', 'main');
() => void
Set a callback to be called when the flow is compete, meaning the user has finished all of the steps available to them.
Useful for performing an action after the flow is complete, such as displaying a congratulations or starting a payment process.
() => void
Set a callback to be called when the user abandons the flow before finalizing it.
Note that this is only possible if your style set defines a close button.
(url: string) => void
Set a callback to handle URL redirects yourself, instead of allowing Formsort to handle them. If not defined, the Formsort embed will handle redirecting the parent page.
This is helpful if you're embedding Formsort within a single-page app that has custom URL route handling.
By default, the web embed accesses the production formsort servers. If you would like to point to another flow server, set origin
in the config to the correct base URL, for example:
new FormsortWebEmbed(document.body, { origin: 'http://localhost:4040'})
FAQs
Embed Formsort flows within other webpages
The npm package @formsort/web-embed-api receives a total of 1,953 weekly downloads. As such, @formsort/web-embed-api popularity was classified as popular.
We found that @formsort/web-embed-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.